package wm.samsung.main;

import java.io.IOException;

import wm.samsung.persistence.DataBaseHelper;
import android.app.Activity;
import android.content.Intent;
import android.database.SQLException;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class ingresoActivity extends Activity {
	private EditText usuario;
	private EditText clave;
	private Button botonSalir2;
	private Button botonIngreso;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ingreso);
		DataBaseHelper myDbHelper;
		myDbHelper = new DataBaseHelper(this);

		try {

			myDbHelper.createDataBase();

		} catch (IOException ioe) {

			throw new Error("Unable to create database");

		}

		try {

			myDbHelper.openDataBase();

		} catch (SQLException sqle) {

			throw sqle;

		}

		usuario = (EditText) findViewById(R.id.usuarioText);
		botonSalir2 = (Button) findViewById(R.id.btnSalirFormIngreso);
		botonIngreso = (Button) findViewById(R.id.btnIngresar);
		botonIngreso.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				ingresar();
			}
		});
		botonSalir2.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				setResult(RESULT_OK);
				finish();
			}
		});
	}

	public void ingresar() {
		Intent i = new Intent(getBaseContext(), agendaActivity.class);
		startActivity(i);
	}

	protected void onSaveInstanceState(Bundle instanceState) {
		super.onSaveInstanceState(instanceState);
		instanceState.putInt("visualState", usuario.getVisibility());
	}

	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		super.onRestoreInstanceState(savedInstanceState);
		usuario.setVisibility(savedInstanceState.getInt("visualState"));
	}
}
